﻿namespace CAION2.Classes
{
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;

    using Models;
    using Properties;

    public static class StigmaSet
    {
        public static readonly Dictionary<int, List<int>> RequiredStigmaChains; 

        static StigmaSet()
        {
            RequiredStigmaChains = new Dictionary<int, List<int>>
            {
                {1, new List<int> {2, 3, 4, 5, 6, 7, 8}},
                {2, new List<int> {4, 5, 6, 7, 8}},
                {3, new List<int> {7, 8}},
                {4, new List<int> {6, 7}},
                {5, new List<int> {8}}
            };
        }
        
        public static IEnumerable<DataRow> CreateMaxStigmaListFromTable(DataTable table)
        {
            string groupName = "";

            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (table.Rows[i]["skill_group_name"].ToString() == groupName) continue;
                
                groupName = table.Rows[i]["skill_group_name"].ToString();
                yield return table.Rows[i];
            }
        }

        public static Dictionary<string, DataRow> CreateStigmaListForStigma(string skillGroupName, bool currentRace)
        {
            string fields = "name, translate" + DataModel.EngFix + " AS translate, desc_long" + DataModel.EngFix + " AS desc_long, "
                            + "skillicon_name, level, quality, require_shard, skill_group_name, "
                            + "warrior, scout, mage, cleric, engineer, artist, fighter, knight, assassin, ranger, wizard, elementalist, chanter, priest, gunner, bard, rider, "
                            + "abyss_point, charge_set_name, cost_parameter, cost_end, cost_end_lv, required_sword, required_mace, "
                            + "required_dagger, required_2hsword, required_polearm, required_staff, required_bow, required_orb, required_book, "
                            + "required_gun, required_cannon, required_harp, casting_delay, delay_time, first_target, require_skill1, "
                            + "require_skill2, instant_skill, race_permitted, cost_time";

            string raceLine = "pc_dark";
            if (!currentRace) raceLine = "pc_light";

            string condition = " skill_group_name = '" + skillGroupName + "'"
                            + " AND level IS NOT NULL "
                            + " AND race_permitted LIKE '%" + raceLine + "%' "
                            + " ORDER BY chain_category_level ASC";

            DataTable stigmasTable = DataModel.GetTable("Stigmas", fields, condition);
            return stigmasTable.Rows.Cast<DataRow>().ToDictionary(row => row["name"].ToString());
        }

        public static string GetGroupOfTopStigma(string className, bool isDef)
        {
            if (className == Resources.Class_Fighter) return isDef ? "FI_BurserkLance" : "FI_DrainSword";
            if (className == Resources.Class_Knight) return isDef ? "KN_InvinsibleProtect" : "KN_DestructShield";

            if (className == Resources.Class_Assassin) return isDef ? "AS_SilentBurst" : "AS_VenomSlash";
            if (className == Resources.Class_Ranger) return isDef ? "RA_LightningShot" : "RA_PainArrow";

            if (className == Resources.Class_Wizard) return isDef ? "WI_IcyShield" : "WI_ZeroPoint";
            if (className == Resources.Class_Elementalist) return isDef ? "EL_HellCurse" : "EL_Order_Omen";

            if (className == Resources.Class_Priest) return isDef ? "PR_HealersHand" : "PR_CallLightning";
            if (className == Resources.Class_Chanter) return isDef ? "CH_ImprovedBody" : "CH_SlowCrash";

            if (className == Resources.Class_Rider) return isDef ? "RI_EathiumWall" : "RI_PowerSlam";
            if (className == Resources.Class_Gunner) return isDef ? "GU_SunningShot" : "GU_MentalicCannon";

            if (className == Resources.Class_Bard) return isDef ? "BA_SongofBless" : "BA_SongofGale";

            return "";
        }
    }
}


